<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>剪切板的使用Clipboard</title>
  <!-- https://www.ruanyifeng.com/blog/2021/01/clipboard-api.html -->
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <button id="btn1">复制剪贴板里面的文本数据</button>
</body>
<script>
  "use strict"; {
    document.getElementById("btn1").addEventListener("click", async e => {
      try {
        let text = await navigator.clipboard.readText()
        console.log(text)
      } catch (err) {
        console.error(`用户不允许使用剪切板功能`, JSON.stringify(err));
      }
    })

    document.getElementById("btn2").addEventListener("click", async e => {
      
    })
  };
</script>

</html>